package com.woniuxy.student.consumer;

import com.rabbitmq.client.Channel;
import com.woniuxy.commons.entity.wyh.DivideClasses;
import com.woniuxy.student.controller.DivideStudent;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author weizihan
 * @Date 2020/7/21 2020/7/21
 * @Description 学生消息接收
 * @Since version-1.0
 */
@Component
public class DivideStudentMessage {
    //webSocket
    @Autowired
    private DivideStudent divideStudent;

    @RabbitListener(queues = "divideClassQueue")
    public void receiveed(Message message, DivideClasses divideClasses, Channel channel)throws IOException{
        System.out.println("接收到了"+new Date());
        System.out.println("消息是："+message.getBody());
        System.out.println(divideClasses);

            //由websocket将消息推送到前端
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
            divideStudent.senMessage(divideClasses.getBeginTime()+","+divideClasses.getEndTime()+","+divideClasses.getTeamType());
    }
}
